package com.it.sqzx.comtroller;

import com.it.sqzx.pojo.Order;
import com.it.sqzx.pojo.User;
import com.it.sqzx.service.OrderService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * projectName: springCloud
 *
 * @author: 王宝贵
 * time: 2024/9/13 20:14 周五
 * description:
 */

@RestController
@Slf4j
public class OrderController
{

    @Value("${server.port}")
    private String port;

    @Resource
    private OrderService orderService ;

    @PostMapping(value = "/order/add")
    public boolean addUser(@RequestBody Order order) {
        return orderService.save(order);
    }

   /* @GetMapping(value = "/order/get/{userId}")
    public Order findUserByUserId(@PathVariable(value = "userId") Long userId) {
        System.out.println("********User Module port: "+port);

        return orderService.getById(userId) ;
    }*/


    @GetMapping(value = "/order/get/{orderId}")
    public Order findOrderByOrderId(@PathVariable("orderId") Long orderId) {
        System.out.println("----Order Module port: "+port);
        Order retValue = orderService.getById(orderId);
        retValue.setExtrainfo(retValue.getExtrainfo()+" \t 服务端口:"+port);
        return retValue;
    }
    /**
     * 查看订单拥有者信息
     * @param orderId
     * @return
     */
    @GetMapping(value = "/order/owner/{orderId}")
    public User findOrderOwner(@PathVariable("orderId") Long orderId) {
        return orderService.findOrderOwner(orderId);
    }
}

